from sqlalchemy import create_engine, Column, Integer, String, Table, MetaData
from sqlalchemy.ext.declarative import declarative_base

from scrapy.utils.project import get_project_settings

DeclarativeBase = declarative_base()


def db_connect():
    return create_engine(get_project_settings().get("CONNECTION_STRING"))


def create_table(engine):
    DeclarativeBase.metadata.create_all(engine)


class BiliDB(DeclarativeBase):
    __tablename__ = 'spdier'
    id = Column(Integer, primary_key=True)  # 主键自增
    url = Column(String(100))
    anime_name = Column(String(100))
    media_id = Column(String(100))
    media_tags = Column(String(100))
    media_info_count_item_play = Column(String(100))
    media_info_count_item_fans = Column(String(100))
    media_info_count_item_review = Column(String(100))
    short_comment = Column(String(200))
    long_comment = Column(String(100))
    score = Column(String(100))
    score_all_people = Column(String(10000))
    order = Column(String(300))
